﻿<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="html" encoding="utf-8" indent="yes" omit-xml-declaration="yes"/>
	<xsl:variable name="tableName" select="report/header/title/text()"/>
	
	<!-- =======================================================
		Template:		 MASTER Template.
		To do:		 Collect all templates to generate .
		Author:		 Dat Le.
		Created Date:	 17 June 2011.
		Last Modified:	 27 June 2011. 
	======================================================= -->
	<xsl:template match="/">
		<xsl:text disable-output-escaping="yes">&lt;%@ page contentType="text/html; charset=UTF-8" %&gt;&#xa;</xsl:text>
		<html>
			<head>
				<title>
					<xsl:text>New </xsl:text>
					<xsl:value-of select="$tableName"/>
				</title>
				
				<link href="style.css" type="text/css" rel="stylesheet" />
				<link rel="stylesheet" href="css/datepicker.css" />
				<script type="text/javascript" language="javascript" src="js/datepicker.js"></script>
				<xsl:text>&#xa;</xsl:text>
				<script language="javascript">
					<xsl:apply-templates select="report/section[@name='Columns']/table" mode="function_empty"/>
					<xsl:apply-templates select="report/section[@name='Columns']/table" mode="function_checkInput"/>
					<xsl:apply-templates select="report/section[@name='Columns']/table" mode="function_showHide"/>
				</script>
				<xsl:text>&#xa;</xsl:text>
			</head>
			<body>
				<TABLE class="tbmain" width="100%">
					<TR HEIGHT="150">
						<TD  align="center" colspan="5">
							<xsl:text disable-output-escaping="yes">&lt;%@include file="top.jsp"%&gt;</xsl:text>
						</TD>
					</TR>
					<TR HEIGHT="12"><TD colspan="5" bgcolor="black"></TD></TR>
					<TR HEIGHT="518">
						<TD class="tdleft">
							 <xsl:text disable-output-escaping="yes">&lt;%@include file="left.jsp"%&gt;</xsl:text>
						</TD>
						<TD bgcolor="black" width="1%"></TD>
						<TD class="tdbody">
							<form name="fmInsert"  method="post" onsubmit="return checkInput();">
								<xsl:attribute name="action">
									<xsl:value-of select="$tableName"/>
									<xsl:text>Servlet</xsl:text>
								</xsl:attribute>
								<fieldset>
									<legend>
										<xsl:text>New </xsl:text>
										<xsl:value-of select="$tableName"/>
									</legend>
									<table>
										<xsl:apply-templates select="report/section[@name='Columns']/table" mode="JSP_INSERT"/>
									</table>
									<input type="submit" value="Insert" />
									<input type="reset" value="Reset" />
								</fieldset>
							</form>
						</TD>
						<TD bgcolor="black" width="1%"></TD>
						<TD class="tdright" vAlign="top">
							<xsl:text disable-output-escaping="yes">&lt;%@include file="right.jsp"%&gt;</xsl:text>
						</TD>
					</TR>
					<TR HEIGHT="12"><TD colspan="5" bgcolor="black"></TD></TR>
					<TR HEIGHT="100">
						<TD colspan="5" align="center">
							<xsl:text disable-output-escaping="yes">&lt;%@include file="bottom.jsp"%&gt;</xsl:text>
						</TD>
					</TR>
				</TABLE>
			</body>
		</html>
		
	</xsl:template>
	<!-- =============== END of MASTER Template ===================== -->
	
	<!-- =======================================================
		Template:		 JSP_INSERT.
		To do:		 Make JSP page with form to insert.
		Author:		 Dat Le.
		Created Date:	 17 June 2011.
		Last Modified:	 27 June 2011.
	======================================================= -->
	<xsl:template match="table" mode="JSP_INSERT">      
		<xsl:for-each select="rows/row">
			<xsl:choose>
				<xsl:when test="@c4='Yes' and @c5 != ''">    <!--check sequence  -->	
				</xsl:when>
				<xsl:when test="@c5 != ''">    <!--check default  -->	
				</xsl:when>
				<xsl:when test="@c1='updator' or @c1='deletion_time'">    <!--not use updator and deletion_time  -->	
				</xsl:when>
				<xsl:when test="@c2='boolean' and @c5='' and @c3='Yes'">
					<tr>
						<td>
							<xsl:value-of select="@c1"/>
							<xsl:text>:</xsl:text>
						</td>
						<td>
							<p>
								<xsl:text>yes</xsl:text>
								<input type="radio" value="true">
									<xsl:attribute name="name">
										<xsl:value-of select="@c1" />
									</xsl:attribute>
									<xsl:attribute name="checked">
									</xsl:attribute>
								</input>
								<xsl:text>no</xsl:text>
								<input type="radio" value="true">
									<xsl:attribute name="name">
										<xsl:value-of select="@c1" />
									</xsl:attribute>
								</input>
							</p>
						</td>
						<td></td>
					</tr>
				</xsl:when>
				<xsl:when test="@c2='boolean' and @c5='' and @c3='No'">  
					<tr>
						<td>
							<xsl:value-of select="@c1"/>
							<xsl:text>:</xsl:text>
						</td>
						<td>
							<p>
								<xsl:text>Is null</xsl:text>
								<input type="checkbox" value="null">
									<xsl:attribute name="name">
										<xsl:text>chk_</xsl:text>
										<xsl:value-of select="@c1" />
									</xsl:attribute>
									<xsl:attribute name="onchange">
										<xsl:text>showHide('p_</xsl:text>
										<xsl:value-of select="@c1" />
										<xsl:text>');</xsl:text>
									</xsl:attribute>
								</input>
							</p>
							<p>
								<xsl:attribute name="id">
									<xsl:text>p_</xsl:text>
									<xsl:value-of select="@c1" />
								</xsl:attribute>
								<xsl:text>yes</xsl:text>
								<input type="radio" value="true">
									<xsl:attribute name="name">
										<xsl:value-of select="@c1" />
									</xsl:attribute>
									<xsl:attribute name="checked">
									</xsl:attribute>
								</input>
								<xsl:text>no</xsl:text>
								<input type="radio" value="true">
									<xsl:attribute name="name">
										<xsl:value-of select="@c1" />
									</xsl:attribute>
								</input>
							</p>
						</td>
						<td></td>
					</tr>
				</xsl:when>
				<xsl:otherwise>
					<tr>
						<td>
							<xsl:value-of select="@c1"/>
							<xsl:text>:</xsl:text>
						</td>
						<td>
							<input type="text">
								<xsl:attribute name="name">
									<xsl:value-of select="@c1" />
								</xsl:attribute>
								<xsl:if test="contains(@c2, 'date')">								
									<xsl:attribute name="id">
										<xsl:value-of select="@c1" />									
									</xsl:attribute>								
								</xsl:if>
							</input>
							<xsl:if test="contains(@c2, 'date')">
								<input type="button" value="...">
									<xsl:attribute name="onclick">
										<xsl:text>javascript:displayDatePicker('</xsl:text>
										<xsl:value-of select="@c1" />
										<xsl:text>', this, 'mdy');</xsl:text>
									</xsl:attribute>
								</input>
							</xsl:if>
						</td>
						<td class="err">
							<xsl:attribute name="id">
								<xsl:text>err_</xsl:text>
								<xsl:value-of select="@c1" />
							</xsl:attribute>
						</td>
					</tr>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
	</xsl:template>
	<!-- ====================== END of INSERT =============================== -->
	
	<!-- =======================================================
		Template:		 empty_function.
		To do:		 Make javascript function empty().
		Author:		 Dat Le.
		Created Date:	 22 June 2011.
		Last Modified:	 25 June 2011.
	======================================================= -->
	<xsl:template match="table" mode="function_empty">    
		<xsl:text>&#xa;	function empty()&#xa;	{&#xa;</xsl:text>
		<xsl:for-each select="rows/row">
			<xsl:choose>
				<xsl:when test="@c4='Yes' and @c5 != ''">    <!--check sequence  -->	
				</xsl:when>
				<xsl:when test="@c5 != ''">    <!--check default  -->	
				</xsl:when>
				<xsl:when test="@c1='updator' or @c1='deletion_time'">    <!--not use updator and deletion_time  -->
				</xsl:when>
				<xsl:when test="@c2='boolean'">    
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>		err_</xsl:text>
					<xsl:value-of select="@c1"/>
					<xsl:text>.innerText = "";&#xa;</xsl:text>					
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
		<xsl:text>	}&#xa;</xsl:text>
	</xsl:template>
	<!-- ====================== END of empty() =============================== -->
	
	<!-- =======================================================
		Template:		 checkInput_function.
		To do:		 Make javascript function checkInput().
		Author:		 Dat Le.
		Created Date:	 22 June 2011.
		Last Modified:	 22 June 2011.
	======================================================= -->
	<xsl:template match="table" mode="function_checkInput">    
		<xsl:text>&#xa;	function checkInput()&#xa;	{&#xa;</xsl:text>
		<xsl:text>		empty();&#xa;		var result = true;&#xa;</xsl:text>
		<xsl:for-each select="rows/row">
			<xsl:choose>
				<xsl:when test="@c4='Yes' and @c5 != ''">    <!--check sequence  -->	
				</xsl:when>
				<xsl:when test="@c5 != ''">    <!--check default  -->	
				</xsl:when>
				<xsl:when test="@c1='updator' or @c1='deletion_time'">    <!--not use updator and deletion_time  -->
				</xsl:when>
				<xsl:when test="@c2='boolean'">    
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>		if(document.fmInsert.</xsl:text>
					<xsl:value-of select="@c1"/>
					<xsl:text>.value=="")&#xa;</xsl:text>		
					<xsl:text>		{&#xa;</xsl:text>	
					<xsl:text>			err_</xsl:text>	
					<xsl:value-of select="@c1"/>
					<xsl:text>.innerText=" Please input </xsl:text>	
					<xsl:value-of select="@c1"/>
					<xsl:text>";&#xa;</xsl:text>
					<xsl:text>			result = false;&#xa;		}&#xa;</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:for-each>
		<xsl:text>		return result;&#xa;</xsl:text>
		<xsl:text>	}&#xa;</xsl:text>
	</xsl:template>
	<!-- ====================== END of empty() =============================== -->
	
	<!-- =======================================================
		Template:		 showHide_function.
		To do:		 Make javascript function showHide().
		Author:		 Dat Le.
		Created Date:	 27 June 2011.
		Last Modified:	 27 June 2011.
	======================================================= -->
	<xsl:template match="table" mode="function_showHide">    
		<xsl:text>&#xa;	function showHide(shID)&#xa;	{&#xa;</xsl:text>
		<xsl:text>		if(document.getElementById(shID).style.display == 'none')&#xa;</xsl:text>
		<xsl:text>			document.getElementById(shID).style.display = 'block';&#xa;</xsl:text>
		<xsl:text>		else&#xa;</xsl:text>
		<xsl:text>			document.getElementById(shID).style.display = 'none';&#xa;</xsl:text>
		<xsl:text>	}&#xa;</xsl:text>
	</xsl:template>
	<!-- ====================== END of showHide() =============================== -->
</xsl:stylesheet>
